package org.meb.conquest.db.model;

import java.util.Arrays;

public enum Faction {

	ASTRA_MILITARUM, SPACE_MARINES, TAU, ELDAR, DARK_ELDAR, CHAOS, ORK, NEUTRAL;

	private static Faction[] alliesCircle = Arrays.copyOf(values(), 7);

	public static Faction[] alliesCircle() {
		return Arrays.copyOf(alliesCircle, alliesCircle.length);
	}

	public Faction[] allies() {
		Faction[] allies;
		if (this == NEUTRAL) {
			allies = new Faction[0];
		} else {
			allies = new Faction[3];
			allies[0] = alliesCircle[(ordinal() - 1 + alliesCircle.length) % alliesCircle.length];
			allies[1] = alliesCircle[(ordinal() + 1) % alliesCircle.length];
			allies[2] = NEUTRAL;
		}
		return allies;
	}
	
	public Faction[] alliance() {
		Faction[] alliance;
		if (this == NEUTRAL) {
			alliance = new Faction[0];
		} else {
			alliance = new Faction[4];
			alliance[0] = alliesCircle[(ordinal() - 1 + alliesCircle.length) % alliesCircle.length];
			alliance[1] = this;
			alliance[2] = alliesCircle[(ordinal() + 1) % alliesCircle.length];
			alliance[3] = NEUTRAL;
		}
		return alliance;
	}
}
